package Objects 
{
	import flash.display.MovieClip;
	import flash.ui.Keyboard;
	import flash.events.KeyboardEvent;
	/**
	 * ...
	 * @author ...
	 */
	public class Hero extends MovieClip
	{
		var velocity:Number = 5.3;
		
		var right:Boolean = false;
		var left:Boolean = false;
		var up:Boolean = false;
		var down:Boolean = false;
		
		public function Hero()
		{
			Main.getInstance().stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPress, false, 0, true);
			Main.getInstance().stage.addEventListener(KeyboardEvent.KEY_UP, onKeyRelease, false, 0, true);
		}
		
		public function update():void
		{
			move();
		}
		private function move():void
		{
			if (right)
			{
				this.x += velocity;
			}
			else if (left)
			{
				this.x -= velocity;
			}
			else if (up)
			{
				this.y -= velocity;
			}
			else if (down)
			{
				this.y += velocity
			}
		}
		
		private function onKeyPress(e:KeyboardEvent):void
		{
			switch(e.keyCode)
			{
				case Keyboard.RIGHT:
					right = true;
				break;
				
				case Keyboard.LEFT:
					left = true;
				break;
				
				case Keyboard.UP:
					up = true;
				break;
				
				case Keyboard.DOWN:
					down = true;
				break;
			}
		}
		
		private function onKeyRelease(e:KeyboardEvent):void
		{
			switch(e.keyCode)
			{
				case Keyboard.RIGHT:
					right = false;
				break;
				
				case Keyboard.LEFT:
					left = false;
				break;
				
				case Keyboard.UP:
					up = false;
				break;
				
				case Keyboard.DOWN:
					down = false;
				break;
			}
		}
	}

}